//
//  CacheClean.m
//  E家
//
//  Created by dllo on 15/10/16.
//  Copyright © 2015年 S1mpl3. All rights reserved.
//

#import "CacheClean.h"

@implementation CacheClean

#warning 路径下单个文件的大小
+(long long)fileSizeAtPath:(NSString *)path{
    NSFileManager *manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:path]) {
        return [[manager attributesOfItemAtPath:path error:nil] fileSize];
    }
    return 0;
}

#warning caches路径文件夹大小
+(float)folderSizeAtpath:(NSString *)path{
    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:path]) {
        return 0;
    }
    NSEnumerator *enumerator = [[manager subpathsAtPath:path] objectEnumerator];
    NSString *fileName = [NSString string];
    float folderSize = 0;
    while ((fileName = [enumerator nextObject]) != nil) {
        folderSize += [self fileSizeAtPath:[path stringByAppendingPathComponent:fileName]];
    }
    return folderSize / 1024.0 / 1024.0;
}

#warning 清除cache路径下的文件
+(void)cleanSizeAtPath:(NSString *)path{
    NSFileManager *manager = [NSFileManager defaultManager];
    if ([manager fileExistsAtPath:path]) {
        NSArray *fileNameArray = [manager subpathsAtPath:path];
        for (NSString *fileName in fileNameArray) {
            [manager removeItemAtPath:[path stringByAppendingPathComponent:fileName] error:nil];
        }
    }
}

@end
